package cn.zn.controller.monitor;

import cn.zn.base.annotation.Log;
import cn.zn.base.bean.dto.ResultData;
import cn.zn.base.common.enums.BusinessType;
import cn.zn.base.common.utils.ResultUtil;
import cn.zn.monitor.service.UserOnlineService;
import cn.zn.monitor.vo.UserOnlinePageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 在线用户监控
 *
 * @author zn-admin
 */
@RestController
@RequestMapping("/monitor/online")
public class UserOnlineController {

    @Autowired
    private UserOnlineService userOnlineService;

    @PreAuthorize("@ss.hasPermi('monitor:online:list')")
    @GetMapping("/list")
    public ResultData list(UserOnlinePageVo vo) {
        Object result = userOnlineService.selectUserOnlineList(vo);
        return ResultUtil.success(result);
    }

    /**
     * 强退用户
     */
    @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
    @Log(title = "在线用户", businessType = BusinessType.FORCE)
    @DeleteMapping("/{tokenId}")
    public ResultData forceLogout(@PathVariable String tokenId) {
        userOnlineService.forceLogout(tokenId);
        return ResultUtil.success();
    }
}
